import Fly from 'flyio'
import request from 'request'
import { getToken } from '.././utils/util'

const fly = new Fly()
fly.config.baseURL = 'http://toutiao.itheima.net/v1_0'
fly.config.timeout = 5000

fly.interceptors.request.use(request => {
  const token = getToken()

  request.headers['X-Tag'] = 'flyio'
  if(token){
    request.headers.Authorization = 'Bearer ' + token
  }
  return request
})

fly.interceptors.response.use(
  response => {
    return request.data
  },
  err => {
	
  }
)

export default fly
